import java.util.Formatter;

/**
 * Keeps track of DVD transactions. 
 * Note: Not all transactions are in total effect immediately.
 */
public class DVDTransaction {
	public static final String STATUS_RENTAL = "R";
	public static final String STATUS_SALE = "S";
	public static final String STATUS_NA = " ";
	
	private int code;
	private String dvdName;
	private int numberOfCopies; 	
	private String rentalStatus;//? questionably useful
	private int priceInCents;
	
	/**
	 * Retrieves DVD transaction code
	 * @return the code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * Retrieves DVD name
	 * @return the name
	 * */
	public String getDVDName() {
		return dvdName;
	}
	
	/**
	 * Returns the transaction, formatted for use in the transaction file
	 * @return transaction string
	 */
	public String toTransactionString(){
		final int TRANS_CODE_SIZE = 2;
		final int TRANS_NAME_SIZE = 25;
		final int TRANS_NUMBER_SIZE = 3;
		final int TRANS_STATUS_SIZE = 1;
		final int TRANS_PRICE_SIZE = 6;
		
		StringBuilder sb = new StringBuilder();
		
		sb.append(FormatUtil.padFrontWithZeros(code, TRANS_CODE_SIZE));
		sb.append(' ');
		sb.append(FormatUtil.padEndWithSpaces(dvdName, TRANS_NAME_SIZE));
		sb.append(' ');
		sb.append(FormatUtil.padFrontWithZeros(numberOfCopies, TRANS_NUMBER_SIZE));
		sb.append(' ');
		sb.append(rentalStatus);
		sb.append(' ');
		sb.append(FormatUtil.padFrontWithZeros(priceInCents/100,TRANS_PRICE_SIZE-3)+'.'
				+FormatUtil.padFrontWithZeros(priceInCents%100,TRANS_PRICE_SIZE-4));
		
		return sb.toString();
	}
	
	/**
	 * Create a new DVD transaction
	 * @param transCode transaction code
	 * @param name name of DVD in transaction
	 * @param copies copies of DVD 
	 * @param rental status of rental
	 * @param priceCents price in cents of the transaction
	 */
	public DVDTransaction(int transCode, String name, int copies, String rental, int priceCents){
		code = transCode;
		dvdName = name;
		numberOfCopies = copies;
		rentalStatus = rental;
		priceInCents = priceCents;
	}
}